import $ from 'jQuery';
(function () {
  let $accountBox = null;
  let $vue = new Vue({
    el: '.main-hook',
    data: {
      leaseType: [{id: 1, name: '短租'}, {id: 2, name: '长租'}],
      receiveStatus: [{id: 1, name: '部分收货'}, {id: 2, name: '全部收货'},{id: 3, name: '订单取消'}],
      orderStatus: [{id: 0, name: '未审核'}, {id: 1, name: '已审核'}, {id: 2, name: '已完结'}, {id: 3, name: '已废弃'}],
      paymentFlag: [{id: 1, name: '未打款'}, {id: 2, name: '已打款至第三方银行'}, {id: 3, name: '已收款'}],
      boxs: {
        box1: {show: true, hook: '.box1-hook', lock: true, url: '', params: {}},
        box2: {show: false, hook: '.box2-hook', url: '', params: {}},
        box3: {show: false, hook: '.box3-hook', url: '', params: {}},
        box4: {show: false, hook: '.box4-hook', url: '', params: {}}
      },
      roleList: []
    },
    created: function () {
      M.Request.getRoleList(true, (roleList, ret) => {
        this.roleList = roleList;
      });
    },
    methods: {
      emitPage: function () {
        M.Page.load(this.boxs);
      },
      // 上一页
      prePage: function () {
        M.Page.prePage(this.boxs);
      },
      searchKey: function () {
        $('.search-hook').trigger('click');
      },
      // 触发刷新页(当前显示的页面)
      refreshPage: function () {
        M.Page.refreshPage(this.boxs);
      },
      exportOrder: function () { //下载
        // var staticServer = $('#staticServer').val();
        IOT.showOverlay('正在导出，请稍等...');
        IOT.getServerData(URI.REPORT.SINGLELIGHT_CONDITION.EXPORT, {}, (ret) => {
          IOT.tips(ret.msg || '操作失败，请重试！', 'error', 1000, null);
          IOT.hideOverlay();
          if (ret && ret.code === 200) {
            window.location.href = ret.data.substr(1);
            // console.log(window.location.href);
            IOT.tips('导出完成！', 'success');
          } else {
            IOT.tips(ret.message || '服务器请求失败，稍后再试！', 'error');
          }
        });
        return false;
      }
    },
    mounted: function () {
      let thiz = this;
      this.$nextTick(() => {
        let tableHookName = '.singleLight-condition-table-hook';
        $accountBox = $('.singleLight-condition-hook');
        var $form = $accountBox.find('.form-hook');
        modal.initDate("startdate","enddate");
        // 查询
        $form.off('submit').on('submit', function () {
          $(tableHookName).bootstrapTable('onCustomSearch');
          return false;
        });
        var $tableHook = $accountBox.find(tableHookName).bootstrapTable({
          scrollbar: 'singleLight-condition-table-body',
          striped: true, // 设置为 true 会有隔行变色效果
          pagination: true, // true 显示分页
          paginationDetail: true, // 分页详情
          sidePagination: 'server', // 服务器端
          method: 'post',
          url: URI.REPORT.SINGLELIGHT_CONDITION.LIST,
          debug: false,
          cache: false,
          pageNumber: 1,
          pageSize: 20,
          pageList: [10, 20, 50, 100],
          // fixedColumns: true,
          customButton: '',
          customQueryParams: function (params) {
            var formParams = $form.serializeJson();
            var queryParams = $.extend({}, params, formParams);
            //console.log(queryParams);
            return queryParams;
          },
          onLoadSuccess: function (data) {
            //console.log(JSON.stringify(data));
          },
          onLoadError: function (status, xhr) {
          },
          onCheckAll: function (rows) {

          },
          columns: [
            {
              field: 'userName', title: '项目名称', align: 'center', fixedLeft: true, tips: true
            },
            {
              field: 'mobile', title: '项目分组', align: 'center', fixedLeft: true,tips: true
            },
            {
              field: 'gender', title: '单灯ID', align: 'center', fixedLeft: true, tips: true
            },
            {
              field: 'gender', title: '灯盏序号', align: 'center', fixedLeft: true, tips: true
            },
            {
              field: 'userName', title: '单灯名称', align: 'center', fixedLeft: true, tips: true
            },
            {
              field: 'mobile', title: '亮度', align: 'center', fixedLeft: true, tips: true
            },
            {
              field: 'mobile', title: '电压', align: 'center', fixedLeft: true, tips: true
            },
            {
              field: 'mobile', title: '电流', align: 'center', fixedLeft: true, tips: true
            },
            {
              field: 'mobile', title: '功率', align: 'center', fixedLeft: true, tips: true
            },
            {
              field: 'registerTime', title: '上报时间', align: 'center', fixedLeft: true, tips: true,
              formatter: function (val, row, index) {
                return val;
            }
            },
          ]
        });
      });
    }
  });
})();